package com.habbot.beautifyinghandbook;

import com.google.ads.Ad;
import com.google.ads.AdListener;
import com.google.ads.AdView;
import com.google.ads.AdRequest.ErrorCode;

import android.graphics.Color;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

public abstract class BaseActivity extends FragmentActivity implements
		OnClickListener {
	ImageView nav_ic_left, nav_ic_right;
	View nav_layout;
	TextView nav_title;
	AdView adView;
	View adLayout;
	abstract void initComponents();

	abstract void addListeners();

	public void addNavigation(String title, int leftIconRes, int rightIconRes) {
		nav_layout = findViewById(R.id.nav_layout);
		nav_ic_left = (ImageView) findViewById(R.id.nav_ic_left);
		nav_ic_right = (ImageView) findViewById(R.id.nav_ic_right);
		nav_title = (TextView) findViewById(R.id.nav_title);
		if (nav_layout != null) {
			nav_layout.setVisibility(View.VISIBLE);
			if (title == null)
				nav_title.setVisibility(View.INVISIBLE);
			else {
				nav_title.setText(title);
				nav_title.setVisibility(View.VISIBLE);
			}

			if (leftIconRes != 0) {
				nav_ic_left.setImageResource(leftIconRes);
				nav_ic_left.setVisibility(View.VISIBLE);
			} else
				nav_ic_left.setVisibility(View.INVISIBLE);
			if (rightIconRes != 0) {
				nav_ic_right.setImageResource(rightIconRes);
				nav_ic_right.setVisibility(View.VISIBLE);
			} else
				nav_ic_right.setVisibility(View.INVISIBLE);
		}

	}

	public void setNavigationBackground(int resDrawable) {
		if (nav_layout != null)
			if (resDrawable == 0)
				nav_layout.setBackgroundColor(Color.TRANSPARENT);
			else
				nav_layout.setBackgroundResource(resDrawable);
	}

	public void setNavIcLeftClickListener(View.OnClickListener listener) {
		nav_ic_left.setOnClickListener(listener);
	}

	public void setNavIcRightClickListener(View.OnClickListener listener) {
		nav_ic_right.setOnClickListener(listener);
	}

	public void setTitleSize(int size) {
		nav_title.setTextSize(size);
	}

	public void setTitleColor(int color) {
		nav_title.setTextColor(color);
	}

	public void initAdView(int id) {
		adView = (AdView) findViewById(id);
		adLayout = findViewById(R.id.ad_layout);
		adView.setAdListener(new AdListener() {

			@Override
			public void onReceiveAd(Ad arg0) {
				adLayout.setVisibility(View.VISIBLE);
			}

			@Override
			public void onPresentScreen(Ad arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onLeaveApplication(Ad arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onDismissScreen(Ad arg0) {
			}
		});
	}

}
